package cn.edu.scau.cmi.liangzijian.factory;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.liangzijian.simpleFactoryMethod.meat.Meat;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;


public class FactoryUIController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button create;

    @FXML
    private ComboBox<String> factoryTypeComboBox;

    @FXML
    private TextArea screen;

    private String factoryType = "";

    private MeatFactory mf = null;
    
    @FXML
    void product(MouseEvent event) {
    	StringBuilder sb = new StringBuilder();
    	
    	switch(factoryType) {
    	case "beef factory":
    		mf = new BeefMeatFactory();
    		sb.append("Beef factory products beef. ");
    		break;
    	case "pork factory":
    		mf = new PorkMeatFactory();
    		sb.append("Pork factory products pork. ");
    		break;
    	case "chicken factory":
    		mf = new ChickenMeatFactory();
    		sb.append("Chicken factory products chicken. ");
    	}
    	
    	//mf = BuildingFactory.getBuildingFactory(factoryType);
    	
    	Meat meat = mf.getMeat();
    	if(meat != null) {
    		sb.append(meat.cook());
    		sb.append("\n");
    		screen.appendText(sb.toString());
    	} 
    }

    @FXML
    void initialize() {
        assert create != null : "fx:id=\"create\" was not injected: check your FXML file 'FactoryUI.fxml'.";
        assert factoryTypeComboBox != null : "fx:id=\"factoryTypeComboBox\" was not injected: check your FXML file 'FactoryUI.fxml'.";
        assert screen != null : "fx:id=\"screen\" was not injected: check your FXML file 'FactoryUI.fxml'.";

        factoryTypeComboBox.setItems(FXCollections.observableArrayList("beef factory", "pork factory", "chicken factory"));
        factoryTypeComboBox.valueProperty().addListener(new ChangeListener() {
			@Override
			public void changed(ObservableValue observable, Object oldValue, Object newValue) {
				factoryType = (String)newValue;
			}    	
    	});
        
    }

}
